package com.wmcsk;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.wmcsk.dl.dl.internal.DLPluginManager;
import com.wmcsk.dl.util.LogUtils;
import com.wmcsk.interfaces.InitResultListener;
import com.wmcsk.interfaces.KuaiyanSelectShareSdkInterface;
import com.wmcsk.interfaces.SignActivityStartListener;

import sdkshell.kuaiyan.com.kuaiyansdk.SdkInit;
import sdkshell.kuaiyan.com.kuaiyansdk.bean.ApkNames;


/**
 * Created by wm on 2017/12/20.
 */
public class KuaiyanSelectShareSdk implements KuaiyanSelectShareSdkInterface {
    private static KuaiyanSelectShareSdk kuaiyanSdk;
    public static final String ERROR_TAG = "KuaiyanSignSdk";
    public static int SHARE_CODE=2018122;
    private KuaiyanSelectShareSdk(){

    }
    private KuaiyanSelectShareSdkInterface kuaiyanSelectShareSdkInterface;
    public void initKYSdkInterface(KuaiyanSelectShareSdkInterface kuaiyanSelectShareSdkInterface){
        this.kuaiyanSelectShareSdkInterface = kuaiyanSelectShareSdkInterface;
    }
    public static KuaiyanSelectShareSdk getInstance(){
        if(kuaiyanSdk == null){
            synchronized (KuaiyanSdk.class){
                if(kuaiyanSdk == null){
                    kuaiyanSdk = new KuaiyanSelectShareSdk();
                }
            }
        }
        return kuaiyanSdk;
    }
    @Override
    public String getVersion() {
        if(kuaiyanSelectShareSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSelectShareSdkInterface.getVersion();
    }

    @Override
    public void init(Context context, InitResultListener initResultListener) {
        if(kuaiyanSelectShareSdkInterface == null) {
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            if(initResultListener!=null){
                initResultListener.initResult(-10);
            }
            return;
        }
        kuaiyanSelectShareSdkInterface.init(context,initResultListener);
    }

    @Override
    public String getSdkInfo() {
        if(kuaiyanSelectShareSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSelectShareSdkInterface.getSdkInfo();
    }

    @Override
    public void startSignActivity(Activity activity,Bundle bundle, SignActivityStartListener signActivityStartListener) {
        if(kuaiyanSelectShareSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            if(signActivityStartListener!=null){
                signActivityStartListener.lunchSignActivityError(-10,"初始化未完成",new RuntimeException("初始化未完成"));
            }
            return;
        }
        Log.d("startSignActivity","success");
        if(bundle!=null){
            bundle.setClassLoader(DLPluginManager.getInstance(SdkInit.getContext()).getPackage(ApkNames.getPackageName(ApkNames.ShareSdk)).classLoader);
        }
        kuaiyanSelectShareSdkInterface.startSignActivity(activity,bundle,signActivityStartListener);
    }
}
